import os
import sys
import xlrd
import django
import xlrd
from xlrd import xldate_as_tuple

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.extend([BASE_DIR, ])
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "finance_c2c.settings")
django.setup()

from apps.supply_order.models import PostCompany


def create_post_company(xlsx):
    data = xlrd.open_workbook(xlsx)  # 打开excel
    table = data.sheets()[0]
    rows = table.nrows  # 行数
    for i in range(0, rows):
        row_values = table.row_values(i)  # 某一行数据
        print(row_values)
        PostCompany.objects.get_or_create(
            name=row_values[0],
            code=row_values[1]
        )


if __name__ == '__main__':
    f = "kuaidi100.xls"
    create_post_company(f)
